package com.sloth.service.impl;

/**
 * @author lai
 * @time 2021/11/1 16:11
 */

import com.sloth.pojo.Myorder;
import com.sloth.service.MyOrderService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 生产者
 */
@Service
public class MsgSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private MyOrderService myOrderService;

    public void addMyOrderMsg(Integer myOrderId , Long deadTime){
        /*Myorder myorder = myOrderService.getMyOrderByMyOrderID(myOrderId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CorrelationData correlationData = new CorrelationData(String.valueOf(myOrderId));
        rabbitTemplate.convertAndSend("myOrderExchange","routingKeyMyOrder",myorder,
                message -> {
                    // 设置一个过期时间，测试时间为一分钟
                    message.getMessageProperties().setHeader("",deadTime * 1000);
                    return message;
                },
                correlationData);
        System.out.println("订单延迟发送成功： " + sdf.format(new Date()));
    */
    }

}